package com.credithc.eagleeye.demo.service.impl;
import com.credithc.eagleeye.demo.dao.DemoUserMapper;
import com.credithc.eagleeye.demo.entity.DemoUser;
import com.credithc.eagleeye.demo.entity.DemoUserExample;
import com.credithc.eagleeye.demo.service.DemoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 描 述: <br/>
 * 作 者: zhangjin<br/>
 * 创 建：2018年09月23日<br/>
 * 版 本：v1.0.0<br>
 * <p>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
@Service
public class DemoServiceImpl implements DemoService {
    @Autowired
    private DemoUserMapper demoUserMapper;
    @Autowired
    private RpcServiceImpl rpcService;

    @Override
    public int saveUser(DemoUser demoUser) {
        return this.demoUserMapper.insert(demoUser);
    }

    @Override
    public PageInfo<DemoUser> queryUser(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        DemoUserExample example = new DemoUserExample();
        example.createCriteria().andNameEqualTo("张三").andAgeEqualTo(18);
        List<DemoUser> demoUsers = demoUserMapper.selectByExample(example);
        for(DemoUser user : demoUsers) {
            String s = rpcService.invokeRemote(user.getName(), user.getAge());
        }
        return new PageInfo<>(demoUsers);
    }

}
